Imports MetaSapiens.PageMethods

''' <summary>
''' Demonstrates the use of array or custom types as parameters.
''' </summary>
Partial Class Serialization
  Inherits MetaSapiens.PageMethods.BasePageWithoutDefaultMethod

  Private Function ArrayToString(ByVal array As Array) As String
    Dim stringBuilder As StringBuilder

    stringBuilder = New StringBuilder()
    stringBuilder.Append("[")
    For i As Integer = 0 To array.Length - 1
      If i > 0 Then
        stringBuilder.Append(",")
      End If
      stringBuilder.Append(array.GetValue(i))
    Next
    stringBuilder.Append("]")

    Return stringBuilder.ToString()
  End Function

  <PageMethod()> _
  Public Sub DisplayArray(<ParamRequired()> ByVal value As String())
    LiteralArray.Text = ArrayToString(value)

    FieldSetArray.Visible = True
  End Sub

  <PageMethod()> _
  Public Sub DisplayCustomObject(<ParamRequired()> ByVal value As CustomObject)
    LiteralInteger.Text = value.AnInteger.ToString()
    LiteralString.Text = value.AString
    LiteralDateTime.Text = value.ADateTime.ToString()
    LiteralDecimal.Text = value.ADecimal.ToString()
    LiteralCustomObjectArray.Text = ArrayToString(value.AnArray)
    LiteralStruct.Text = value.AStruct.ToString()
    LiteralSubObject.Text = value.ASubObject.ToString()

    FieldSetCustomObject.Visible = True
  End Sub


  <PageMethod()> _
  Public Sub DisplayCustomObjectWithTypeConverter(<ParamRequired()> value as CustomObject3)
    LiteralX.Text = value.X.ToString()
    LiteralY.Text = value.Y.ToString()

    FieldSetTypeConverter.Visible = True
  End Sub
End Class
